package fivecardstudd;


public class AI {
	  public enum RoundStatus {
          INACTIVE, WAITING_FOR_TURN, IN_TURN, JUST_BET, WON;
  }
  
   String AIname;
  int numberOfAI=0;
  String AILevel="";
  private int chips;
  private int lastBet;
  private Table table; 
  private Hand currentHand;
  private RoundStatus roundStatus;
  
  
	public AI(int chips, Table table) {
		 this.chips = chips;
         lastBet = 0;
         this.table = table;
         currentHand = new Hand();
         roundStatus = RoundStatus.INACTIVE; 
		numberOfAI++;
	}
	
	
	public int getNumberOfAIs(){
		return numberOfAI;
	}
	
 public void SetAIname(){
		this.AIname="AIPowered"+(int)(Math.random() * 100);
	
		}
	
	
	public String getAIname(){
		return AIname;
		}
	

        public int getChips() {
          return chips;
        }
  
        public void setChips(int chips) {
          this.chips = chips;
        }
   
        public int getLastBet() {
            return lastBet;
        }
 
        public void resetLastBet(){
           lastBet = 0;
        }

        public Hand getCurrentHand() {
            return currentHand;
         }

        public void setCurrentHand(Hand currentHand) {
            this.currentHand = currentHand;
        }

        public RoundStatus getRoundStatus() {
            return roundStatus;
       }

          public void setRoundStatus(RoundStatus roundStatus) {
             this.roundStatus = roundStatus;
         }
          
          public int getValueOfCard(int n) {
             return currentHand.getHand().get(n).asInt();
        }
  

        public void handReset(){
              currentHand.reset();
        }
  

         public void setActive(){
             this.setRoundStatus(RoundStatus.WAITING_FOR_TURN);
         }
  

         public void setTurn(){
            this.setRoundStatus(RoundStatus.IN_TURN);
       }
  
 
        public boolean inTurn(){
             return this.getRoundStatus() == RoundStatus.IN_TURN;
        }
  

         public boolean getActive(){
               return this.getRoundStatus() != RoundStatus.INACTIVE;
         }
  
  
         public boolean hasBet(){
             return this.getRoundStatus() == RoundStatus.JUST_BET;
         }  
  

         public void addCardToHand(Card c) {
               currentHand.addCard(c);
         }
  
 
       public void bet(int betAmount){
              chips = chips - betAmount;
              table.increasePot(betAmount);
              lastBet += betAmount;

       
              System.out.println(this+", you just bet "+betAmount+" you have "+chips+" chips left");
       }
  

        public void call(){
            if(table.getCurrentBet()-lastBet >= chips){
                  bet(chips);
            }
            else{
                  bet(table.getCurrentBet()-lastBet);
            }
          
            setRoundStatus(RoundStatus.JUST_BET);
        }
  
 
       public void raise(int bet){
          table.setCurrentBet(table.getCurrentBet()+bet);
          call();
       }
  

       public void allIn(){
          table.setCurrentBet(chips);
          bet(chips);
          setRoundStatus(RoundStatus.JUST_BET);
      }
  

      public void fold(){
          this.setRoundStatus(RoundStatus.INACTIVE);
     }
  

     public void wonHand(int winnings){
        
          chips += winnings;
          setRoundStatus(RoundStatus.WON);
     }
   
   
   
   @Override
   public String toString() {
           return "ai";
   }
   
	
}